package com.jeesite.modules.home.web;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.home.entity.DcProvinceMajor;
import com.jeesite.modules.home.service.DcProvinceMajorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: ciye
 * @date: 2022/3/14 16:48
 */
@Controller
@RequestMapping(value = "${adminPath}/home/provinceMajor")
public class DcProvinceMajorController extends BaseController {

    @Autowired
    private DcProvinceMajorService dcProvinceMajorService;

    /**
     * 导入Excel信息
     * @param file
     * @param updateFlag
     * @return
     */
    @RequestMapping("/importInfo")
    @ResponseBody
    public String infoImport(MultipartFile file, String updateFlag) {
        String resultWord = dcProvinceMajorService.infoImport(file, updateFlag);
        if (resultWord.contains("成功")) {
            return renderResult(Global.TRUE, resultWord);
        } else {
            return renderResult(Global.FALSE, resultWord);
        }
    }

    /**
     * 查询列表
     */
    @RequestMapping("/list")
    public String list(DcProvinceMajor dcProvinceMajor, Model model) {
        model.addAttribute("dcProvinceMajor", dcProvinceMajor);
        return "modules/home/leaderHomeProvince";
    }

    /**
     * 查询经济指标数据
     * @param dcProvinceMajor
     * @param request
     * @param response
     * @return
     */
    @RequestMapping("/listData")
    @ResponseBody
    public Page<DcProvinceMajor> listData(DcProvinceMajor dcProvinceMajor, HttpServletRequest request, HttpServletResponse response){
        Page page = new Page<>(request, response);
        List<DcProvinceMajor> list = dcProvinceMajorService.getProvinceMajor(dcProvinceMajor.getPublishYearMonth());
//        page.setList(list).setCount(list.size());
        page.setList(list);
        return page;
    }

    /**
     * 查询主要经济指标排名
     * @param publishYearMonth
     * @param cityName
     * @return
     */
    @RequestMapping("/getRank")
    public Map getProvinceMajorRank(String publishYearMonth, String cityName){
        Map map = dcProvinceMajorService.getProvinceMajorRank(publishYearMonth, cityName);
        return map;
    }
}
